<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once 'core/base/BaseObj.php';
require_once 'core/app/AppObj.php';

require_once APP_MODULE_DIR . 'member/inc/Member.php';
require_once APP_MODULE_DIR . 'member/inc/MemberModel.php';


class KBClientView_register extends KBClientView_common
{
	
	var $update = false;
	
	
	function KBClientView_register() {
		
		parent::KBClientView();
		$this->obj = new Member;
		
		$file = $this->getMsgFile('user_msg.ini', false);
		$this->msg = array_merge($this->msg, AppMsg::parseMsgs($file));
	}
	

	function &execute(&$manager) {
		
		if($this->update) { $title = $this->msg['update_member_msg']; } 
		else              { $title = $this->msg['register_msg']; }
		
		$this->home_link = true;
		$this->meta_title = '';
		
		$data = $this->getTop($manager, $title, false);
		$data .= $this->getForm($manager, $title);
		
		return $data;		
	}
	

	function getForm($manager, $title) {
		
		$tpl = &new tplTemplatez($this->template_dir . 'register_form.html');
		$auth = &new AuthPriv();
		if($this->update) {
			$tpl->tplSetNeededGlobal('update');
			
			$val = ($_POST) ? $_POST['remember'] : $auth->getCookie();
			$val = ($val) ? 'checked' : '';
			$tpl->tplAssign('remember_option', $val);
		}
		
		$tpl->tplAssign('id', $manager->user_id);
		$tpl->tplAssign('title_msg', $title);
		$tpl->tplAssign('action_link', $this->_getLink('all'));
		$tpl->tplAssign('cancel_link', $this->_getLink());															  
		$tpl->tplAssign('user_msg', $this->getErrors());
		
		if($this->useCaptcha($manager, 'register')) {
			$tpl->tplSetNeeded('/captcha');
			$tpl->tplAssign('captcha_src', $this->getCaptchaSrc());
		}		
		
		// not change checkbox
		@$val = ($_POST) ? $_POST['not_change_pass'] : 1;
		$val = ($val) ? 'checked' : '';
		$tpl->tplAssign('pass_change_checked', $val);
		
		
		$tpl->tplAssign($this->msg);
		$tpl->tplAssign($this->getFormData());
		
		$tpl->tplParse();
		return $tpl->tplPrint(1);
	}	
	
	
	
	function validate($values, $manager, $manager_1) {
		
		$this->obj->validate($values, $manager_1);
		if($this->obj->errors) {
			return $this->obj->errors;
		}
		
		
		$v =& new Validator($values, false);
		
		if($this->useCaptcha($manager, 'register')) {
			if($_SESSION['kb_captcha_'] != $values['captcha']) {
				$v->setError('captcha_text_msg', 'captcha', 'captcha');
			}
		}		
		
		return $v->getErrors();		
	}
}
?>